package com.bytedance.scenedemo.group.tab;

import com.bytedance.scene.Scene;
import com.bytedance.scene.ui.ResourceTable;
import com.bytedance.scene.ui.template.AppCompatScene;
import com.bytedance.scene.ui.template.BottomNavigationViewScene;
import com.bytedance.scene.ui.template.ItemInfo;
import com.bytedance.scenedemo.utility.ColorUtil;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
import ohos.agp.utils.TextAlignment;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

public class BottomNavigationViewSample extends BottomNavigationViewScene {


    @Override
    protected LinkedHashMap<String, Scene> getSceneMap() {
        LinkedHashMap map = new LinkedHashMap<String, Scene>();
        map.put("主页", TabChildScene.newInstance(0));
        map.put("搜索", TabChildScene.newInstance(1));
        map.put("通知", TabChildScene.newInstance(2));
        return map;
    }

    @Override
    protected List<ItemInfo> getTabList() {
        List<ItemInfo> list = new ArrayList<>();
        ItemInfo itemInfo = new ItemInfo();
        itemInfo.setTabName("主页");
        itemInfo.setColor(0xff4050B5);
        itemInfo.setIcon(ResourceTable.Media_ic_home_white_24dp);
        list.add(itemInfo);

        ItemInfo itemInfo2 = new ItemInfo();
        itemInfo2.setTabName("搜索");
        itemInfo2.setColor(0xff4050B5);
        itemInfo2.setIcon(ResourceTable.Media_sousuo);
        list.add(itemInfo2);

        ItemInfo itemInfo3 = new ItemInfo();
        itemInfo3.setTabName("通知");
        itemInfo3.setColor(0xff4050B5);
        itemInfo3.setIcon(ResourceTable.Media_ic_favorite_white_24dp);
        list.add(itemInfo3);
        return list;
    }

    public static class TabChildScene extends AppCompatScene {
        /**
         * 空的构造函数
         */
        private TabChildScene() {}

        public static TabChildScene newInstance(int index){
            TabChildScene tabChildScenen = new TabChildScene();
            IntentParams intentParams = new IntentParams();
            intentParams.setParam("index",index);
            tabChildScenen.setArguments(intentParams);
            return tabChildScenen;
        }
        @Override
        protected Component onCreateContentView(LayoutScatter inflater, ComponentContainer container, Intent savedInstanceState) {
            Text text = new Text(requireSceneContext());
            ComponentContainer.LayoutConfig config = new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,ComponentContainer.LayoutConfig.MATCH_PARENT);
            text.setLayoutConfig(config);
            IntentParams intentParams = getArguments();
            int index = (int) intentParams.getParam("index");
            text.setBackground(ColorUtil.getMaterialColor(index));
            text.setTextColor(Color.BLACK);
            text.setTextSize(16, Text.TextSizeType.FP);
            text.setTextAlignment(TextAlignment.CENTER);
            text.setText("Child Scene #"+index);
            return text;
        }

        @Override
        public void onViewCreated(Component component, Intent intent) {
            super.onViewCreated(component, intent);
            setTitleVisiable(Component.HIDE);
        }
    }
}
